package ar.fiuba.tp7552.buildadmin.tags;

import java.io.IOException;
import java.io.Writer;

import org.apache.struts2.components.Component;

import com.opensymphony.xwork2.util.ValueStack;

public class PaginateTableFilter extends Component {

	private String tableId;
	private boolean filter;
	
	public PaginateTableFilter(ValueStack stack) {
		super(stack);
	}
	
	public boolean start(Writer writer) {
		try {
			writer.write("<script type=\"text/javascript\">");
			writer.write("$(document).ready(function() {");
			writer.write("$('#"+tableId+"').dataTable( {");
			if (!filter) {
				//bFilter
				writer.write("\"bFilter\": false,");
			}
			
			writer.write("\"sPaginationType\": \"full_numbers\",");
			writer.write("\"bSort\": false,");
			writer.write("\"bLengthChange\": false,");
			writer.write("\"oLanguage\": {");
			writer.write("\"sProcessing\":\"Procesando...\",");
			writer.write("\"sLengthMenu\":\"Mostrar _MENU_ registros\",");
			writer.write("\"sZeroRecords\":\"No se encontraron resultados\",");
			writer.write("\"sInfo\":\"Mostrando desde _START_ hasta _END_ de _TOTAL_ registros\",");
			writer.write("\"sInfoEmpty\":\"Mostrando desde 0 hasta 0 de 0 registros\",");
			writer.write("\"sInfoFiltered\":\"(filtrado de _MAX_ registros en total)\",");
			writer.write("\"sInfoPostFix\":\"\",");
			writer.write("\"sSearch\":\"Filtrar:\",");
			writer.write("\"sUrl\":\"\",");
			writer.write("\"oPaginate\":{");
			writer.write("\"sFirst\":\"Primero\",");
			writer.write("\"sPrevious\":\"Anterior\",");
			writer.write("\"sNext\":\"Siguiente\",");
			writer.write("\"sLast\":\"Ultimo\"");
			writer.write("}}});});</script>");
		} catch (IOException ioe) {
            ioe.printStackTrace();
		}
        return true;
    }

	public String getTableId() {
		return tableId;
	}

	public void setTableId(String tableId) {
		this.tableId = tableId;
	}

	public boolean isFilter() {
		return filter;
	}

	public void setFilter(boolean filter) {
		this.filter = filter;
	}	
}
